package com.itany.corejava.day15;

public class Test2 extends Thread {

    private String s="";


    public static void main(String[] args) {
        Test2 t=new Test2();
        t.start();
        t.f();

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(t.getS().length());


    }

    @Override
    public void run() {
        f();
    }

//    private synchronized void f(){
//        for (int i = 0; i < 300; i++) {
//            s+="1";
//        }
//    }


    private void f(){
        for (int i = 0; i < 300; i++) {
            synchronized (this) {
                s += "1";
            }
        }
    }

    public String getS() {
        return s;
    }

    public void setS(String s) {
        this.s = s;
    }
}
